#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> frequencySort(vector<int>& nums) {
        unordered_map<int, int> hash;
        for (auto& e : nums) hash[e]++;

        sort(nums.begin(), nums.end(), [&hash](int n1, int n2) {
            if (hash[n1] == hash[n2])
                return n1 > n2;
            else
                return hash[n1] < hash[n2];
            });

        return nums;
    }
};